function res = viewDemodSpectrum(obj, nCol, varargin)
%VIEWDEMODSPECTRUM Summary of this function goes here
%   Detailed explanation goes here
    p=inputParser; p.KeepUnmatched = true; p.PartialMatching = false;
    p.addRequired('nCol', @(x) x > 2 );
    
    p.addParameter('name',     'Spectrum', @ischar);
    p.addParameter('mode',     ziEnumGridMode.Linear, @ziEnumGridMode.test);
    p.addParameter('fSpan',      1e3,     @(x) x>0);
    p.addParameter('average',    1,       @(x) x>0);
    p.addParameter('fft_window',  ziEnumFFTWindow.Hann,   @ziEnumFFTWindow.test);
    
    p.addParameter('trig_device',  '',                           @(x) ismember(x, obj.deviceSerials) || isempty(x));
    p.addParameter('trig_node',    [],                           @(x) isa(x, 'ziStreamNode') || isempty(x));
    p.addParameter('edge',         ziEnumTrigEdgeSlope.Positive, @ziEnumTrigEdgeSlope.test);
    p.addParameter('level',        0.0,                          @isnumeric);
    p.addParameter('hysteresis',   0.0,                          @isnumeric);
    p.addParameter('count',        1,                            @(x) x>0);
    p.addParameter('bits',         1,                            @(x) isa(x, 'int64') );
    p.addParameter('bitmask',      1,                            @(x) isa(x, 'int64') );
    p.addParameter('holdofftime',  0.0,                          @(x) x>=0.0 );
    p.addParameter('holdoffcount', 0,                            @(x) x>=0 );
    p.addParameter('delay',       -0.1,                          @isnumeric );
    
    p.parse(nCol, varargin{:});
    
    spect = obj.spectrumModule(p.Results.name);
    spect.initialize();
    spect.setFrequencyGrid(p.Results.nCol, 'fSpan', p.Results.fSpan);
    spect.setAverage(p.Results.average);
    spect.setFFTWindow(p.Results.fft_window);
    
    if ~isempty(p.Results.trig_node) && ~isempty(p.Results.trig_device)
        spect.setTrigger(p.Results.trig_device, p.Results.trig_node, ...
                        'edge',         p.Results.edge, ...
                        'level',        p.Results.level, ...
                        'hysteresis',   p.Results.hysteresis, ...
                        'count',        p.Results.count, ...
                        'bits',         p.Results.bits, ...
                        'bitmask',      p.Results.bitmask, ...
                        'holdofftime',  p.Results.holdofftime, ...
                        'holdoffcount', p.Results.holdoffcount, ...
                        'delay',        p.Results.delay);
    end
    
    if ~isempty(obj.demodSignalNodes)
        for k = 1:size(obj.demodSignalNodes, 1)
            spect.subscribe(obj.demodSignalNodes{k, :});
        end
    else
        error('No node subscribed.');
    end
    
    res=spect.run();
    spect.unsubscribe();
end

